import random

# 定义角色
ROLES = ["狼人", "村民", "预言家", "女巫", "猎人"]

# 分配角色
def assign_roles(num_players):
    roles = []
    # 简单分配，可根据需求调整
    num_wolves = max(1, num_players // 4)
    roles.extend(["狼人"] * num_wolves)
    roles.extend(["村民"] * (num_players - num_wolves - 3))
    roles.extend(["预言家", "女巫", "猎人"])
    random.shuffle(roles)
    player_roles = {i + 1: role for i, role in enumerate(roles)}
    return player_roles

# 夜晚行动
def night_action(player_roles):
    wolves = [player for player, role in player_roles.items() if role == "狼人"]
    if wolves:
        print("狼人请睁眼，选择要击杀的玩家：")
        for wolf in wolves:
            print(f"狼人 {wolf} 请输入要击杀的玩家编号：")
            target = int(input())
            print(f"狼人 {wolf} 选择击杀玩家 {target}")
    seer = [player for player, role in player_roles.items() if role == "预言家"]
    if seer:
        print("预言家请睁眼，选择要查验的玩家：")
        for s in seer:
            target = int(input())
            if player_roles[target] == "狼人":
                print(f"预言家 {s} 查验得知玩家 {target} 是狼人")
            else:
                print(f"预言家 {s} 查验得知玩家 {target} 是好人")
    witch = [player for player, role in player_roles.items() if role == "女巫"]
    if witch:
        print("女巫请睁眼，是否使用解药或毒药（输入 1 使用解药，2 使用毒药，其他跳过）：")
        choice = input()
        if choice == '1':
            print("请输入要救的玩家编号：")
            target = int(input())
            print(f"女巫救了玩家 {target}")
        elif choice == '2':
            print("请输入要毒的玩家编号：")
            target = int(input())
            print(f"女巫毒了玩家 {target}")

# 白天投票
def day_vote(player_roles):
    print("白天到了，开始投票环节，请每个玩家输入要投票的玩家编号：")
    votes = {}
    for player in player_roles.keys():
        vote_target = int(input(f"玩家 {player} 请输入要投票的玩家编号："))
        if vote_target in votes:
            votes[vote_target] += 1
        else:
            votes[vote_target] = 1
    max_votes = 0
    voted_out = []
    for target, vote_count in votes.items():
        if vote_count > max_votes:
            max_votes = vote_count
            voted_out = [target]
        elif vote_count == max_votes:
            voted_out.append(target)
    if len(voted_out) == 1:
        print(f"玩家 {voted_out[0]} 被投票出局，其角色是 {player_roles[voted_out[0]]}")
    else:
        print("本轮投票平票，无人出局")

# 主游戏流程
def play_game(num_players):
    player_roles = assign_roles(num_players)
    print("角色分配完成，游戏开始！")
    for player, role in player_roles.items():
        print(f"玩家 {player} 的角色是 {role}")
    while True:
        print("夜晚来临...")
        night_action(player_roles)
        print("白天来临...")
        day_vote(player_roles)
        # 这里可以添加判断游戏结束的逻辑，例如狼人或好人全部出局
        # 简单示例，暂未完善
        input("按回车键进入下一轮...")

if __name__ == "__main__":
    num_players = int(input("请输入玩家数量："))
    play_game(num_players)